package com.example.larou.mapper;

import com.example.larou.entity.Order;
import com.example.larou.entity.OrderInfRes;
import com.example.larou.entity.Product;
import com.example.larou.entity.Store;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;

public interface TbProduct {
    @Results(id = "productMap", value = {
            @Result(property = "product_name", column = "product_name"),
            @Result(property = "price", column = "price"),
            @Result(property = "img", column = "img"),
            @Result(property = "description", column = "description"),
            @Result(property = "stock", column = "stock"),
            @Result(property = "category_id", column = "category_id"),
            @Result(property = "store_id", column = "store_id")
    })
    @Select("SELECT * FROM tb_products WHERE #{id} IS NULL OR id LIKE CONCAT('%', #{id}, '%')")
    List<Product> getAllProducts(@Param("id") String id);


    @Select("SELECT Store_ID, Store_Name, Owner_Name, Store_URL, Store_Description, " +
            "Store_Rating, Number_of_Followers, Number_of_Products, Total_Sales, Contact_Number, " +
            "Email_Address, Physical_Address," +
            "  Categories, Business_Hours, Customer_Service_Rating, " +
            "Shipping_Rating, Return_Policy, Store_Logo_URL " +
            "FROM Taobao_Store_Info WHERE store_id = #{storeId}")
    List<Store> getShopinf(String store_id);
@Select("SELECT store_ID FROM tb_products WHERE id=#{id}")
    String getShopID(@Param("id") String id);

    @Insert("INSERT INTO tb_orders (order_number, payment_method, product_id, user_id, address, status, payment_time, deal_time, quantity, price,shop_id) " +
            "VALUES (#{order.orderNumber}, #{order.paymentMethod}, #{order.productId}, #{order.userId}, #{order.address}, #{order.status}, #{order.paymentTime}, #{order.dealTime}, #{order.quantity}, #{order.price},#{order.shopId})")
    boolean createOrder(@Param("order")Order order);

    @Select("SELECT id, order_number, payment_method, product_id, user_id, address, status, payment_time, deal_time, quantity, price, create_time, update_time " +
            "FROM tb_orders WHERE user_id = #{userId}")
    List<Order> getOrderById(@Param("userId") int userId);
    @Select("SELECT o.id,o.price as product_real_price,o.quantity, o.status ," +
            "(SELECT p.product_name FROM tb_products p WHERE p.id = o.product_id) AS product_name," +
            "(SELECT p.img FROM tb_products p WHERE p.id = o.product_id) AS product_img," +
            "(SELECT p.description FROM tb_products p WHERE p.id = o.product_id) AS product_description," +
            "(SELECT p.price FROM tb_products p WHERE p.id = o.product_id) AS product_price," +
            "(SELECT s.store_name FROM Taobao_Store_Info s WHERE s.store_id = o.shop_id) AS shop_name " +
            "FROM tb_orders o WHERE o.user_id = #{userId}")
    List<OrderInfRes> getProductByUserId(int userId);
    @Delete("DELETE FROM tb_orders WHERE id = #{id}")
    Boolean deleteOrder(@Param("id") String id);
}






